package org.lql.algo.codecrush.week008;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: liangqinglong
 * @date: 2025-08-18 23:56
 * @description: 1. 两数之和 <a href="https://leetcode.cn/problems/two-sum/description/">...</a>
 **/
public class TwoSum {

	public int[] twoSum(int[] nums, int target) {
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < nums.length; i++) {
			if (map.containsKey(target - nums[i])) {
				return new int[]{map.get(target - nums[i]), i};
			}
			map.put(nums[i], i);
		}
		return new int[]{};
	}

	public static void main(String[] args) {
		TwoSum twoSum = new TwoSum();
		System.out.println(Arrays.toString(twoSum.twoSum(new int[]{2, 7, 11, 15}, 9)));
		System.out.println(Arrays.toString(twoSum.twoSum(new int[]{2, 7, 11, 15}, 1)));
	}
}
